package com.smartleanx.module.hrm.service.employee.listenser;

import com.smartleanx.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEvent;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEventListener;
import com.smartleanx.module.hrm.eums.employee.ProcessDefinitionEnum;
import com.smartleanx.module.hrm.service.employee.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 员工晋升流程状态监听器
 */
@Slf4j
@Component
public class BpmEmployeePromotedListener extends BpmProcessInstanceStatusEventListener {
    @Resource
    private EmployeeService employeeService;


    @Override
    protected String getProcessDefinitionKey() {
        return ProcessDefinitionEnum.PROMOTED.getKey();
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        if (BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(event.getStatus())) {
            System.out.println("pass");
            employeeService.approvedChangePost(Long.valueOf(event.getBusinessKey()), event.getStatus());
        } else if (BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(event.getStatus())
                || BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(event.getStatus())) {
            System.out.println("reject");
            employeeService.rejectChangePost(Long.valueOf(event.getBusinessKey()), event.getStatus());
        }
    }
}
